<?php

$s = $_POST['s']??'';
//获取当前文件所在的绝对目录
$dir =  dirname(__FILE__)."/files".(($s)?('/'.$s):'');
$targetIndex = $_POST['target_index'];
$fileArr = $_POST['file_arr'];

$configJsonStr = file_get_contents("config.json");
$config = json_decode($configJsonStr,true);
if(!isset($config['move_target_arr']) || !isset($config['move_target_arr'][$targetIndex])){
	die("移动目录下标不存在");
}
$targetData = $config['move_target_arr'][$targetIndex];
$targetDir = $targetData['dir'];


$num = 0;
foreach($fileArr as $i=> $fileName){
    $fileName = str_replace('/','',$fileName);
	$res = rename($dir.'/'.$fileName, $targetDir.'/'.$fileName);
    $res && $num = $num + 1;
}


echo json_encode($num,JSON_UNESCAPED_UNICODE);